package com.qfhd.soft.cjzcore.Model;

import android.text.TextUtils;

import androidx.annotation.NonNull;

import com.qfhd.soft.cjzcore.Core.CJJsonUtils;
import com.qfhd.soft.cjzcore.Core.CJLogger;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

public class Task_image_detial_step_model {
//    "id":2,
//            "task_id":1,
//            "step_id":1,
//            "step_text":"第一步 下载",
//            "step_image":"13jef9wifjslkjs",
//            "is_delete":0,
//            "created_at":"2020-04-01 12:06:43",
//            "updated_at":"2020-04-01 13:16:10"
    public int id;
    public int task_id;
    public int step_id;
    public String step_text;
    public String step_image;
    public int is_delete;
    public String create_at;
    public String updated_at;

    public boolean imageIsEmpty(){
        if(TextUtils.isEmpty(step_image)){
            return true;
        }else{
            if(step_image.equalsIgnoreCase("null")){
                return true;
            }
            else{
                return false;
            }
        }
    }

    public static Task_image_detial_step_model create(int id,int task_id,String step_text,String step_image){
        Task_image_detial_step_model model = new Task_image_detial_step_model();
        model.id = id;
        model.task_id = task_id;
        model.step_text = step_text;
        model.step_image = step_image;
        return model;
    }

    public static Task_image_detial_step_model getModelByJSONObject(JSONObject object){
        Task_image_detial_step_model model = new Task_image_detial_step_model();
        model.id = CJJsonUtils.getValueFromKey_int(object,"id");
        model.task_id = CJJsonUtils.getValueFromKey_int(object,"task_id");
        model.step_id = CJJsonUtils.getValueFromKey_int(object,"step_id");
        model.step_text = CJJsonUtils.getValueFromKey_string(object,"step_text");
        model.step_image = CJJsonUtils.getValueFromKey_string(object,"step_image");
        model.is_delete = CJJsonUtils.getValueFromKey_int(object,"is_delete");
        model.create_at = CJJsonUtils.getValueFromKey_string(object,"create_at");
        model.updated_at = CJJsonUtils.getValueFromKey_string(object,"updated_at");
        return model;
    }

    public static List<Task_image_detial_step_model> getListByJSONArray(JSONArray array){
        List<Task_image_detial_step_model> list = new ArrayList<>();
        for(int i=0; i<array.length(); i++){
            try {
                list.add(getModelByJSONObject(array.getJSONObject(i)));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return list;
    }

    @NonNull
    @Override
    public String toString() {
        return "id:" + id + " image:" + step_image + " text:" + step_text;
    }
}
